<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" th:href="@{/image/favicon.ico}" type="image/x-icon"/>
    <link rel="stylesheet" th:href="@{/css/oksub.css}"/>
    <script type="text/javascript" th:src="@{lib/loading/okLoading.js}"></script>
    <style>
        #login form.layui-form {
            margin: 0;
            transform: translate(-50%, -50%);
        }

        .register .tit {
            padding-top: 15px;
            text-align: center;
            font-size: 18px;
        }

    </style>
</head>
<body class="page-fill">
    <div class="page-fill register" id="login">
        <form class="layui-form " th:action="@{/registerUser}">
            <div class="layui-form-item tit">注册</div>
            <div class="layui-form-item input-item">
                <label for="userName">用户账号</label>
                <input type="text" lay-verify="required" name="userName" placeholder="请输入账号" autocomplete="off" id="userName" class="layui-input">
            </div>
            <div class="layui-form-item input-item">
                <label for="password">密码</label>
                <input type="password" lay-verify="required|password" name="password" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input">
            </div>
            <div class="layui-form-item input-item">
                <label for="comPassword">确认密码</label>
                <input type="password" lay-verify="required|comPassword" name="comPassword" placeholder="请确认密码" autocomplete="off" id="comPassword" class="layui-input">
            </div>
            <div class="layui-form-item input-item">
                <label for="nickName">昵称（6个字以内）</label>
                <input type="text" lay-verify="required" name="nickName" placeholder="请输入昵称" autocomplete="off" id="nickName" class="layui-input" maxlength="6">
            </div>
            <div class="layui-form-item input-item">
                <label for="email">输入邮箱</label>
                <input type="email" lay-verify="required|email" name="email" placeholder="请输入邮箱地址" autocomplete="off" id="email"  class="layui-input">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-block" lay-filter="login" lay-submit="">注册</button>
            </div>
            <div class="login-link">
                <a th:href="@{/toLogin}">有账号去登录</a>
            </div>
        </form>
    </div>
    <!--js逻辑-->
    <script th:src="@{/lib/layui/layui.js}"></script>
    <script>
      
    </script>
    <script>
        let use = layui.use(["form", "okGVerify", "okLayer"], function () {
            let form = layui.form;
            let layer = layui.layer;
            let $ = layui.jquery;
            let s = "[[${msg2}]]";
            if(s !== ""){
                layer.open({
                    title: '注册错误',
                    content: s,
                    icon: 2
                });
            }

            okLoading.close($);
            
            /**
             * 数据校验
             */
            form.verify({
                password: [/^[\S]{6,12}$/, "密码必须6到12位，且不能出现空格"],
                comPassword: function (val) {
                    let password = $("#password").val();
                    return password === val ? '' : "两次密码不一致";
                }
            });

            /**
             * 表单提交
             */
            form.on("submit(login)", function () {
                //弹出loading
                const index = top.layer.msg('邮件发送中，请稍候', {icon: 16, time: false, shade: 0.8});
                setTimeout(function(){
                    top.layer.close(index);
                    return true;
                },3000);
            });

            /**
             * 表单input组件单击时
             */
            $("#login .input-item .layui-input").click(function (e) {
                e.stopPropagation();
                $(this).addClass("layui-input-focus").find(".layui-input").focus();
            });

            /**
             * 表单input组件获取焦点时
             */
            $("#login .layui-form-item .layui-input").focus(function () {
                $(this).parent().addClass("layui-input-focus");
            });

            /**
             * 表单input组件失去焦点时
             */
            $("#login .layui-form-item .layui-input").blur(function () {
                $(this).parent().removeClass("layui-input-focus");
                if ($(this).val() != "") {
                    $(this).parent().addClass("layui-input-active");
                } else {
                    $(this).parent().removeClass("layui-input-active");
                }
            });

        });
    </script>
</body>
</html>
